<?php
$width=Yii::app()->params['dialog']['findCustomerForBusiness']['width'];
$height=Yii::app()->params['dialog']['findCustomerForBusiness']['height'];
$cs=Yii::app()->clientScript;
$cs->registerScriptFile('./js/modal.js');
$cs->registerScript('business_admin_dialog',<<<END
function Block(){\$.modal('?r=dialog/findCustomerForBusiness&rt=search',{width:$width,height:$height,title:'请选择客户'});return false;}
$("#findCustomer").click(Block);
END
);
?>
<?php if($search):?>
<h2>查询业务记录</h2>
<?php else:?>
<h2>修改业务记录</h2>
<?php endif?>
<?php echo CHtml::beginForm(array($search?'search':'admin'),'post');?>
<table  style="margin: 0 auto;"  width="940px">
<tr><td>
	客户名称：<input id="c_name" type="text" name="keys[customer_name.name]" size="22" value="<?php echo isset($_GET['keys']['customer_name.name'])?$_GET['keys']['customer_name.name']:'';?>"/><input id="findCustomer" type="button" value="?" title="查找客户"/>
	业务类型：<?php echo CHtml::dropDownList('keys[business_detail.business_type]', isset($_GET['keys']['business_detail.business_type'])?$_GET['keys']['business_detail.business_type']:'', array(''=>'全部','0'=>'运输','1'=>'仓储','2'=>'装卸'));?>
	承运方：<?php echo CHtml::dropDownList('keys[business_detail.carrier_type]', isset($_GET['keys']['business_detail.carrier_type'])?$_GET['keys']['business_detail.carrier_type']:'', array(''=>'全部','0'=>'自有车','1'=>'第三方'));?>
	业务时间:从<input type="text" id="keys[s_date]" name="keys[s_date]" size="7" value="<?php echo isset($_GET['keys']['s_date'])?$_GET['keys']['s_date']:'';?>"/>
	<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'keys[s_date]','ifFormat'=>'%Y-%m-%d'));?>
	至<input type="text" id="keys[e_date]" name="keys[e_date]" size="7" value="<?php echo isset($_GET['keys']['e_date'])?$_GET['keys']['e_date']:'';?>"/>
	<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'keys[e_date]','ifFormat'=>'%Y-%m-%d'));?>
	模糊查询：<input type="radio" name="keys[blur]" value="1" checked/>是  
	<input type="radio" name="keys[blur]" value="0" <?php echo isset($_GET['keys']['blur'])&&$_GET['keys']['blur']==0?'checked':'';?>/>否 
	<input type="submit" value="搜索"/>
</td></tr></table>
<?php echo CHtml::endForm();?>
<table class="dataGrid" width="940px">
  <thead>
  <tr>
    <th width="150"><?php echo $sort->link('customer_name'); ?></th>
    <th width="70"><?php echo $sort->link('business_type'); ?></th>
    <th width="50"><?php echo $sort->link('carrier_type'); ?></th>
    <th width="50"><?php echo $sort->link('truck_times'); ?></th>
    <th width="70"><?php echo $sort->link('tonnage'); ?></th>
    <th width="70"><?php echo $sort->link('receivable_amount'); ?></th>
    <th width="70"><?php echo $sort->link('payable_amount'); ?></th>
    <th width="70"><?php echo $sort->link('disparity'); ?></th>
    <th width="70"><?php echo $sort->link('disparity_ratio'); ?></th>
    <th width="70"><?php echo $sort->link('loss_amount'); ?></th>
    <th width="80"><?php echo $sort->link('occur_time'); ?></th>
    <th width="50"><?php echo $sort->link('update_user'); ?></th>
	<?php if(!$search):?><th  width="70">操作</th><?php endif ?>
  </tr>
  </thead>
  <tbody>
<?php $last_page=($pages->getCurrentPage()+1)==$pages->getPageCount();?>
<?php foreach($models as $n=>$model): ?>
  <tr class="<?php echo $n%2?'even':'odd';?>">
    <?php 
    	$url=array('show','id'=>$model->id)+$_GET;//把所有参数包括页码、查询参数传入显示信息页面
    	$url['ret']=$search?'search':'admin';
    ?>
    <td><?php 
    		if($last_page&&$n==(count($models)-1)) echo $model->customer_name; 
    		else echo CHtml::link($model->customer_name,$url); 
        ?>
    </td>
    <td><?php echo CHtml::encode($model->getBusinessTypeName()); ?></td>
    <td><?php echo CHtml::encode($model->getCarrierTypeName()); ?></td>
    <td><?php echo CHtml::encode($model->truck_times); ?></td>
    <td><?php echo CHtml::encode($model->tonnage); ?></td>
    <td><?php echo CHtml::encode($model->receivable_amount); ?></td>
    <td><?php echo CHtml::encode($model->payable_amount); ?></td>
    <td><?php echo CHtml::encode($model->disparity); ?></td>
    <td><?php echo CHtml::encode(($model->disparity_ratio*100).'%'); ?></td>
    <td><?php echo CHtml::encode($model->loss_amount); ?></td>
    <td><?php echo CHtml::encode($model->occur_time); ?></td>
    <td><?php echo CHtml::encode($model->update_user); ?></td>
    <?php if(!$search):?>
    <?php if($last_page&&$n==(count($models)-1)):?>
    <td></td>
    <?php else:?>
    <td>
      <?php echo CHtml::link('修改',array('update','id'=>$model->id)+$_GET); ?>
     <?php echo CHtml::link('删除',array('delete','id'=>$model->id)+$_GET,array('confirm'=>"确定要删除{$model->customer_name}的业务记录吗？")); ?>
	</td>
	<?php endif?>
	<?php endif ?>
  </tr>
<?php endforeach; ?>
  </tbody>
</table>
<br/>
<?php $this->widget('CLinkPager',array('pages'=>$pages,'htmlOptions'=>array('style'=>'width:940px;'))); ?>